import { useState } from 'react';
import {
  LineChartOutlined
} from '@ant-design/icons';
import { v1 as uuid } from 'uuid';
import type { MenuProps } from 'antd';
import { Link } from 'react-router-dom';


/**
 * 根据用户类型生成对应menu
 * @param roleType 用户类型
 * @returns { MENU_DATA } 菜单列表
 */
const useMenu = (roleType?: number | null) => {
  const menuFromRole = (role?: number | null) => {

    let individual = ''; // 个人中心 url
    switch (role) {
      case 1: {
        individual = '';
        break;
      }
      case 2: {
        individual = '';
        break;
      }
      case 3: {
        individual = '';
        break;
      }
      default: individual = '';
    }
    const items: MenuProps['items'] = [
      {
        label: (<Link to={'/'}><span>首页</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      },
      {
        label: (<Link to={'/goutConsultation'}><span>痛风会诊</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      },
      {
        label: (<Link to={'/medicalTraining'}><span>医护培训</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      },
      {
        label: (<Link to={'/demonstrationBase'}><span>示范基地</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      },
      {
        label: (<Link to={'/medicalAlliance'}><span>医联体</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      },
      {
        label: (<Link to={individual}><span>个人中心</span></Link>),
        key: uuid(),
        icon: <LineChartOutlined />
      }
    ]
    return items;
  };

  const [menu, setMenu] = useState(menuFromRole(roleType));

  const setMenuFromRole = (currentRole?: number | null) => {
    setMenu(menuFromRole(currentRole));
  };

  return [menu, { setMenuFromRole }] as const;
};

export default useMenu;
